{include file="common/head"}
<div class="card">
    <div class="card-header">
        <!-- <div class="row">
            <div class="col-md-4">
                <div class="row">
                    <label class="col-sm-4 col-form-label"><span class="text-danger">*</span> 角色搜索</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control pull-left" name="name" value="" placeholder="请输入角色名称">
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <button type="submit" class="btn btn-primary me-1">搜索</button>
                <button type="reset" class="btn btn-default">重置</button>
            </div>
        </div> -->
        <span class="text-primary">添加权限</span>
    </div>
    <div class="card-body">
        <form action="" class="layui-form" lay-filter="add">
            <div class="layui-form-item">
                <label class="col-sm-4 col-form-label"><span class="text-primary">* 权限描述</span></label>
                <div class="col-sm-8">
                    <input type="text" class="form-control pull-left" name="description" value="" placeholder="请输入权限描述">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="col-sm-4 col-form-label"><span class="text-primary">* 请求地址</span></label>
                <div class="col-sm-8">
                    <input type="text" class="form-control pull-left" name="url" value="" placeholder="请输入请求地址">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="col-sm-4 col-form-label"><span class="text-primary">* 选中权限</span></label>
                <select name="pid">
                    <option value="0">新建父权限</option>
                    {volist name="list" id="auth"}
                       <option value="{$auth.id}">{$auth.description}</option>
                    </optgroup>
                    {/volist}
                  </select>
            </div>
            <label class="col-sm-4 col-form-label"><span class="text-primary">* 请求地址</span></label>
            <div class="layui-form-item">
                <button type="submit" class="mt-4 btn btn-primary mb-3" lay-submit lay-filter="add">添加权限</button>
            </div>
        </form>
    </div>
</div>
{include file="common/bottom"}
<script>
    layui.use(function () {
        var form = layui.form
        var layer = layui.layer
        // 提交事件
        form.on('submit(add)', function (data) {
            var field = data.field;
            $.post('/admin/auth/doAdd', field, (res) => {
                if (res.code == 200) {
                    layer.msg('添加成功', { icon: 6 })
                } else {
                    layer.msg('添加失败：' + res.message, { icon: 5 })
                }
            })
            return false; // 阻止默认 form 跳转
        });
    })
</script>